<div class="content-section introduction">
    <div class="feature-intro">
        <h1>Messages</h1>
        <p>Messages is used to display alerts inline.</p>
    </div>
</div>

<div class="content-section implementation">
    <div class="card">
        <h5>Severities</h5>
        <p-messages [(value)]="msgs1" [enableService]="false"></p-messages>

        <h5>Dynamic</h5>
        <button type="button" pButton pRipple (click)="addMessages()" label="Show" class="p-mr-2"></button>
        <button type="button" pButton pRipple (click)="clearMessages()" icon="pi pi-times" label="Clear" class="p-button-secondary"></button>

        <p-messages [(value)]="msgs2" [enableService]="false"></p-messages>

        <h5>Message Service</h5>
        <button type="button" pButton (click)="showViaService()" label="Via Service"></button>
        <p-messages></p-messages>

        <h5>Static Content</h5>
        <p-messages severity="info">
            <ng-template pTemplate>
                <img src="assets/showcase/images/primeng.svg" width="32" />
                <div class="p-ml-2">Always bet on Prime.</div>
            </ng-template>
        </p-messages>

        <h5>Inline Message</h5>
        <p>p-message component is used to display inline messages mostly within forms.</p>
        <p-message severity="info" text="Message Content" styleClass="p-mr-2"></p-message>
        <p-message severity="success" text="Message Content" styleClass="p-mr-2"></p-message>  
        <p-message severity="warn" text="Message Content" styleClass="p-mr-2"></p-message>  
        <p-message severity="error" text="Message Content"></p-message>
        
        <div class="p-mt-4">
            <input type="text" pInputText placeholder="Username" class="ng-dirty ng-invalid p-mr-2">
            <p-message severity="error" text="Field is required"></p-message>
        </div>
        
        <div class="p-mt-4">
            <input type="text" pInputText placeholder="Email" class="ng-dirty ng-invalid p-mr-2">
            <p-message severity="error"></p-message>
        </div>

        <h5>Form Layout</h5>
        <div class="p-field p-fluid">
            <label for="username">Username</label>
            <input id="username" type="username" aria-describedby="username-help" class="p-invalid" pInputText />
            <small id="username-help" class="p-invalid">Username is not available.</small>
        </div>
    </div>    
</div>

<div class="content-section documentation">
    <p-tabView>
        <p-tabPanel header="Documentation">
            <h5>Import</h5>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;MessagesModule&#125; from 'primeng/messages';
import &#123;MessageModule&#125; from 'primeng/message';
</app-code>

            <h5>Getting Started</h5>
            <p>A single message is specified by Message interface in PrimeNG that defines the id, severity, summary and detail as the properties.
                Messages to display can either be defined using the value property which should an array of Message instances or using 
               a MessageService are defined using the value property which should an array of Message instances.</p>

<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-messages [(value)]="msgs"&gt;&lt;/p-messages&gt;
</app-code>
            
            <h5>Message Array</h5>
            <p>A binding to the value property is required to provide messages to the component.</p>

<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-messages [(value)]="msgs"&gt;&lt;/p-messages&gt;

&lt;button type="button" (click)="show()"&gt;Show&lt;/button&gt;
&lt;button type="button" (click)="clear()"&gt;Hide&lt;/button&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
show() &#123;
    this.msgs.push(&#123;severity:'info', summary:'Info Message', detail:'PrimeNG rocks'&#125;);
&#125;

hide() &#123;
    this.msgs = [];
&#125;
</app-code>

            <h5>Message Service</h5>
            <p>MessageService alternative does not require a value binding to an array.
            In order to use this service, import the class and define it as a provider in a component higher up in the component tree such as application instance itself 
            so that descandant components can have it injected. If there are multiple message components having the same message service, you may use key property of the component
            to match the key of the message to implement scoping.</p>
            
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;MessageService&#125; from 'primeng/api';
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;Component&#125; from '@angular/core';
import &#123;Message&#125; from 'primeng//api';
import &#123;MessageService&#125; from 'primeng/api';

@Component(&#123;
    templateUrl: './messagesdemo.html'
    &#125;)
    export class MessageServiceDemo &#123;

        constructor(private messageService: MessageService) &#123;&#125;

        addSingle() &#123;
            this.messageService.add(&#123;severity:'success', summary:'Service Message', detail:'Via MessageService'&#125;);
        &#125;

        addMultiple() &#123;
            this.messageService.addAll([&#123;severity:'success', summary:'Service Message', detail:'Via MessageService'&#125;,
                            &#123;severity:'info', summary:'Info Message', detail:'Via MessageService'&#125;]);
        &#125;
        
        clear() &#123;
            this.messageService.clear();
        &#125;
&#125;
</app-code>

            <h5>Closable</h5>
            <p>Messages are closable by default resulting in a close icon being displayed on top right corner.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-messages [(value)]="msgs"&gt;&lt;/p-messages&gt;
</app-code>

            <p>In order to disable closable messages, set <i>closable</i> to false. Note that in this case two-way binding is not necessary as the component
            does not need to update its value.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-messages severity="info"&gt;
    &lt;ng-template pTemplate&gt;
        &lt;img src="assets/showcase/images/demo/organization/walter.jpg" width="32" /&gt;
        &lt;span class="custom-message"&gt;I am the one who knocks.&lt;/span&gt;
    &lt;/ng-template&gt;
&lt;/p-messages&gt;
</app-code>

            <h5>Severities</h5>
            <p>Here are the possible values for the severity of a message.</p>
            <ul>
                <li>success</li>
                <li>info</li>
                <li>warn</li>
                <li>error</li>
            </ul>

            <h5>Static Content</h5>
            <p>Alternative way to provide the content for the messages is templating. In this case value property and message service is ignored and only static
                is displayed.
            </p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-messages severity="info"&gt;
    &lt;ng-template pTemplate&gt;
        &lt;img src="assets/showcase/images/primeng.svg" width="32" /&gt;
        &lt;div class="p-ml-2"&gt;Always bet on Prime.&lt;/div&gt;
    &lt;/ng-template&gt;
&lt;/p-messages&gt;
</app-code>
            
            <h5>Message Component</h5>
            <p>Message component is useful in cases where messages need to be displayed related to an element such as forms. It has two property, severity and text of the message.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-message severity="info" text="Message Content"&gt;&lt;/p-message&gt;
&lt;p-message severity="success" text="Message Content"&gt;&lt;/p-message&gt;  
&lt;p-message severity="warn" text="Message Content"&gt;&lt;/p-message&gt;  
&lt;p-message severity="error" text="Message Content"&gt;&lt;/p-message&gt;
</app-code>

            <h5>Animation Configuration</h5>
            <p>Transition of the open and hide animations can be customized using the <i>showTransitionOptions</i> and <i>hideTransitionOptions</i> properties, 
                example below disables the animations altogether.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-message [showTransitionOptions]="'0ms'" [hideTransitionOptions]="'0ms'" severity="info" text="PrimeNG Rocks"&gt;&lt;/p-message&gt;
</app-code>
            <h5>Properties of Messages Component</h5>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Default</th>
                        <th>Description</th>
                    </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>value</td>
                            <td>array</td>
                            <td>null</td>
                            <td>An array of messages to display.</td>
                        </tr>
                        <tr>
                            <td>closable</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Defines if message box can be closed by the click icon.</td>
                        </tr>
                        <tr>
                            <td>style</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Inline style of the component.</td>
                        </tr>
                        <tr>
                            <td>styleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the component.</td>
                        </tr>
                        <tr>
                            <td>enableService</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Whether displaying services messages are enabled.</td>
                        </tr>
                        <tr>
                            <td>escape</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Whether displaying messages would be escaped or not.</td>
                        </tr>
                        <tr>
                            <td>key</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Id to match the key of the message to enable scoping in service based messaging.</td>
                        </tr>
                        <tr>
                            <td>showTransitionOptions</td>
                            <td>string</td>
                            <td>300ms ease-out</td>
                            <td>Transition options of the show animation.</td>
                        </tr>
                        <tr>
                            <td>hideTransitionOptions</td>
                            <td>string</td>
                            <td>200ms cubic-bezier(0.86, 0, 0.07, 1)</td>
                            <td>Transition options of the hide animation.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Properties of Message Component</h5>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Default</th>
                        <th>Description</th>
                    </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>severity</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Severity level of the message.</td>
                        </tr>
                        <tr>
                            <td>text</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Text content.</td>
                        </tr>
                        <tr>
                            <td>escape</td>
                            <td>boolean</td>
                            <td>true</td>
                            <td>Whether displaying messages would be escaped or not.</td>
                        </tr>
                        <tr>
                            <td>style</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Inline style of the component.</td>
                        </tr>
                        <tr>
                            <td>styleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the component.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Styling for Messages Component</h5>
            <p>Following is the list of structural style classes, for theming classes visit <a href="#" [routerLink]="['/theming']">theming page</a>.</p>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Element</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>p-messages</td>
                            <td>Container element.</td>
                        </tr>
                        <tr>
                            <td>p-message</td>
                            <td>Message element.</td>
                        </tr>
                        <tr>
                            <td>p-message-info</td>
                            <td>Message element when displaying info messages.</td>
                        </tr>
                        <tr>
                            <td>p-message-warn</td>
                            <td>Message element when displaying warning messages.</td>
                        </tr>
                        <tr>
                            <td>p-message-error</td>
                            <td>Message element when displaying error messages.</td>
                        </tr>
                        <tr>
                            <td>p-message-success</td>
                            <td>Message element when displaying success messages.</td>
                        </tr>
                        <tr>
                            <td>p-message-close</td>
                            <td>Close button.</td>
                        </tr>
                        <tr>
                            <td>p-message-close-icon</td>
                            <td>Close icon.</td>
                        </tr>
                        <tr>
                            <td>p-message-icon</td>
                            <td>Severity icon.</td>
                        </tr>
                        <tr>
                            <td>p-message-summary</td>
                            <td>Summary of a message.</td>
                        </tr>
                        <tr>
                            <td>p-message-detail</td>
                            <td>Detail of a message.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Styling for Message Component</h5>
            <p>Following is the list of structural style classes, for theming classes visit <a href="#" [routerLink]="['/theming']">theming page</a>.</p>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Element</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>p-inline-message</td>
                            <td>Message element.</td>
                        </tr>
                        <tr>
                            <td>p-inline-message-info</td>
                            <td>Message element when displaying info messages.</td>
                        </tr>
                        <tr>
                            <td>p-inline-message-warn</td>
                            <td>Message element when displaying warning messages.</td>
                        </tr>
                        <tr>
                            <td>p-inline-message-error</td>
                            <td>Message element when displaying error messages.</td>
                        </tr>
                        <tr>
                            <td>p-inline-message-success</td>
                            <td>Message element when displaying success messages.</td>
                        </tr>
                        <tr>
                            <td>p-inline-message-icon</td>
                            <td>Severity icon.</td>
                        </tr>
                        <tr>
                            <td>p-inline-message-text</td>
                            <td>Text of a message.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Dependencies</h5>
            <p>None.</p>
        </p-tabPanel>

        <p-tabPanel header="Source">
            <a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/messages" class="btn-viewsource" target="_blank">
                <span>View on GitHub</span>
            </a>
            <a href="https://stackblitz.com/edit/primeng-messages-demo" class="btn-viewsource" style="margin-left: .5em;" target="_blank">
                <span>Edit in StackBlitz</span>
            </a>

<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;h5&gt;Severities&lt;/h5&gt;
&lt;p-messages [(value)]="msgs1" [enableService]="false"&gt;&lt;/p-messages&gt;

&lt;h5&gt;Dynamic&lt;/h5&gt;
&lt;button type="button" pButton pRipple (click)="addMessages()" label="Show" class="p-mr-2"&gt;&lt;/button&gt;
&lt;button type="button" pButton pRipple (click)="clearMessages()" icon="pi pi-times" label="Clear" class="p-button-secondary"&gt;&lt;/button&gt;

&lt;p-messages [(value)]="msgs2" [enableService]="false"&gt;&lt;/p-messages&gt;

&lt;h5&gt;Message Service&lt;/h5&gt;
&lt;button type="button" pButton (click)="showViaService()" label="Via Service"&gt;&lt;/button&gt;
&lt;p-messages&gt;&lt;/p-messages&gt;

&lt;h5&gt;Static Content&lt;/h5&gt;
&lt;p-messages severity="info"&gt;
    &lt;ng-template pTemplate&gt;
        &lt;img src="assets/showcase/images/primeng.svg" width="32" /&gt;
        &lt;div class="p-ml-2"&gt;Always bet on Prime.&lt;/div&gt;
    &lt;/ng-template&gt;
&lt;/p-messages&gt;

&lt;h5&gt;Inline Message&lt;/h5&gt;
&lt;p&gt;p-message component is used to display inline messages mostly within forms.&lt;/p&gt;
&lt;p-message severity="info" text="Message Content" styleClass="p-mr-2"&gt;&lt;/p-message&gt;
&lt;p-message severity="success" text="Message Content" styleClass="p-mr-2"&gt;&lt;/p-message&gt;  
&lt;p-message severity="warn" text="Message Content" styleClass="p-mr-2"&gt;&lt;/p-message&gt;  
&lt;p-message severity="error" text="Message Content"&gt;&lt;/p-message&gt;

&lt;div class="p-mt-4"&gt;
    &lt;input type="text" pInputText placeholder="Username" class="ng-dirty ng-invalid p-mr-2"&gt;
    &lt;p-message severity="error" text="Field is required"&gt;&lt;/p-message&gt;
&lt;/div&gt;

&lt;div class="p-mt-4"&gt;
    &lt;input type="text" pInputText placeholder="Email" class="ng-dirty ng-invalid p-mr-2"&gt;
    &lt;p-message severity="error"&gt;&lt;/p-message&gt;
&lt;/div&gt;

&lt;h5&gt;Form Layout&lt;/h5&gt;
&lt;div class="p-field p-fluid"&gt;
    &lt;label for="username"&gt;Username&lt;/label&gt;
    &lt;input id="username" type="username" aria-describedby="username-help" class="p-invalid" pInputText /&gt;
    &lt;small id="username-help" class="p-invalid"&gt;Username is not available.&lt;/small&gt;
&lt;/div&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
    import &#123;Component, OnInit&#125; from '@angular/core';
    import &#123;Message,MessageService&#125; from 'primeng/api';
    
    @Component(&#123;
        templateUrl: './messagesdemo.html',
        providers: [MessageService]
    &#125;)
    export class MessagesDemo implements OnInit &#123;
    
        msgs1: Message[];
    
        msgs2: Message[];
        
        constructor(private messageService: MessageService) &#123;&#125;
    
        ngOnInit() &#123;
            this.msgs1 = [
                &#123;severity:'success', summary:'Success', detail:'Message Content'&#125;,
                &#123;severity:'info', summary:'Info', detail:'Message Content'&#125;,
                &#123;severity:'warn', summary:'Warning', detail:'Message Content'&#125;,
                &#123;severity:'error', summary:'Error', detail:'Message Content'&#125;
            ];
        &#125;
        
        addMessages() &#123;
            this.msgs2 = [
                &#123;severity:'success', summary:'Success', detail:'Message Content'&#125;,
                &#123;severity:'info', summary:'Info', detail:'Message Content'&#125;,
                &#123;severity:'warn', summary:'Warning', detail:'Message Content'&#125;,
                &#123;severity:'error', summary:'Error', detail:'Message Content'&#125;
            ];
        &#125;
    
        clearMessages() &#123;
            this.msgs2 = [];
        &#125;
    
        showViaService() &#123;
            this.messageService.add(&#123;severity:'success', summary:'Service Message', detail:'Via MessageService'&#125;);
        &#125;
    &#125;
</app-code>
        </p-tabPanel>
        <p-tabPanel header="StackBlitz">
            <ng-template pTemplate="content">
                <iframe src="https://stackblitz.com/edit/primeng-messages-demo?embed=1" style="width: 100%; height: 768px; border: none;"></iframe>
            </ng-template>
        </p-tabPanel>
    </p-tabView>
</div>
